﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 写号工具
{
    public static class PortModel
    {
        /// <summary>
        /// 蓝牙模块通信命令
        /// </summary>
        public static class BtUartModel
        {
            public static byte[] SetScan(byte delay, sbyte level) { return new byte[] { 0xA0, 0xF4, 0x00, 0x02, delay, (byte)level }; }
            public static byte[] SetScanOk { get { return new byte[] { 0xA0, 0xF4, 0x00, 0x00 }; } }

            public static byte[] Scan { get { return new byte[] { 0xA0, 0xF1, 0x00, 0x00 }; } }
            public static byte[] ScanOk { get { return new byte[] { 0xA0, 0xF1, 0x00, 0x00 }; } }

            public static byte[] GetDevices { get { return new byte[] { 0xA0, 0xE1, 0x00, 0x00 }; } }

            public static byte[] Connect(byte[] mac) { return new byte[] { 0xA0, 0xF2, 0x00, 0x06 }.Concat(mac).ToArray(); }
            public static byte[] ConnectOk { get { return new byte[] { 0xA0, 0xF2, 0x00, 0x00 }; } }
            public static byte[] CheckConnect { get { return new byte[] { 0xA0, 0xE2, 0x00, 0x00 }; } }
            public static byte[] CheckConnectWait { get { return new byte[] { 0xA0, 0xE2, 0x00, 0x01, 0x00 }; } }
            public static byte[] CheckConnectOk { get { return new byte[] { 0xA0, 0xE2, 0x00, 0x01, 0x01 }; } }
            public static byte[] CheckConnectNg { get { return new byte[] { 0xA0, 0xE2, 0x00, 0x01, 0x02 }; } }

            public static byte[] DisConnect { get { return new byte[] { 0xA0, 0xF6, 0x00, 0x00 }; } }
            public static byte[] DisConnectOk { get { return new byte[] { 0xA0, 0xF6, 0x00, 0x00 }; } }


            public static byte[] SendFirstBar { get { return new byte[] { 0xA0, 0xF3, 0x00, 0x03, 0x00, 0x00, 0x00 }; } }
            public static byte[] SendBar(byte index, byte[] bar)
            {
                byte lenHigh = (byte)(((bar.Length + 3) >> 8) & 0xff);
                byte lenLow = (byte)((bar.Length + 3) & 0xff);
                byte barLenHigh = (byte)((bar.Length >> 8) & 0xff);
                byte barLenLow = (byte)(bar.Length & 0xff);
                return new byte[] { 0xA0, 0xF3, lenHigh, lenLow, index, barLenHigh, barLenLow }.Concat(bar).ToArray();
            }
            public static byte[] SendBarOk { get { return new byte[] { 0xA0, 0xF3, 0x00, 0x00 }; } }
            public static byte[] CheckBar { get { return new byte[] { 0xA0, 0xE3, 0x00, 0x00 }; } }
            public static byte[] CheckBarWait { get { return new byte[] { 0xA0, 0xE3, 0x00, 0x01, 0x00 }; } }
            public static byte[] CheckBarOk { get { return new byte[] { 0xA0, 0xE3, 0x00, 0x01, 0x01 }; } }
            public static byte[] CheckBarNg { get { return new byte[] { 0xA0, 0xE3, 0x00, 0x01, 0x02 }; } }


            public static byte[] LightLed(byte R, byte G, byte B, byte mode, byte cycle, byte time) { return new byte[] { 0xA0, 0xF5, 0x00, 0x06, R, G, B, mode, time, cycle }; }
            public static byte[] LightLedOk { get { return new byte[] { 0xA0, 0xF5, 0x00, 0x00 }; } }
        }
        /// <summary>
        /// 产品通信命令
        /// </summary>
        public static class ChannelUartModel
        {
            public static byte[] GetMac { get { return new byte[] { 0xA0, 0xF1, 0x00, 0x00 }; } }

            public static byte[] SendPic(byte barCount)
            {
                return new byte[] { 0xA0, 0xF2, 0x00, 0x02, 0x01, barCount };
            }
            public static string SendPicOk { get { return "F2ok"; } }

            public static byte[] SendBarHead(byte index, int barLen)
            {
                byte lenHigh = (byte)(((barLen + 3) >> 8) & 0xff);
                byte lenLow = (byte)((barLen + 3) & 0xff);
                byte barLenHigh = (byte)((barLen >> 8) & 0xff);
                byte barLenLow = (byte)(barLen & 0xff);
                return new byte[] { 0xA0, 0xF3, lenHigh, lenLow, index, barLenHigh, barLenLow };
            }
            public static string SendBarHeadOk { get { return "F3ok"; } }

            public static string SendBarDataOk { get { return "FEok"; } }

            public static byte[] LightRgb { get { return new byte[] { 0xA0, 0xF4, 0x00, 0x00 }; } }
            public static string LightRgbOk { get { return "F4ok"; } }

            public static byte[] SetLowPower { get { return new byte[] { 0xA0, 0xF5, 0x00, 0x00 }; } }
            public static string SetLowPowerOk { get { return "F5ok"; } }
        }
        /// <summary>
        /// 继电器通信命令
        /// </summary>
        public static class RelayUartModel
        {
            public static string AllOn { get { return "01\r\n"; } }
            public static string AllOff { get { return "00\r\n"; } }
            public static string On1 { get { return "11\r\n"; } }
            public static string Off1 { get { return "10\r\n"; } }
            public static string On2 { get { return "21\r\n"; } }
            public static string Off2 { get { return "20\r\n"; } }
            public static string On3 { get { return "31\r\n"; } }
            public static string Off3 { get { return "30\r\n"; } }
            public static string On4 { get { return "41\r\n"; } }
            public static string Off4 { get { return "40\r\n"; } }
            public static string On5 { get { return "51\r\n"; } }
            public static string Off5 { get { return "50\r\n"; } }
            public static string On6 { get { return "61\r\n"; } }
            public static string Off6 { get { return "60\r\n"; } }
            public static string On7 { get { return "71\r\n"; } }
            public static string Off7 { get { return "70\r\n"; } }
            public static string On8 { get { return "81\r\n"; } }
            public static string Off8 { get { return "80\r\n"; } }
            public static string On9 { get { return "91\r\n"; } }
            public static string Off9 { get { return "90\r\n"; } }
            public static string On10 { get { return "101\r\n"; } }
            public static string Off10 { get { return "100\r\n"; } }
            public static string On11 { get { return "111\r\n"; } }
            public static string Off11 { get { return "110\r\n"; } }
            public static string On12 { get { return "121\r\n"; } }
            public static string Off12 { get { return "120\r\n"; } }
            public static string On13 { get { return "131\r\n"; } }
            public static string Off13 { get { return "130\r\n"; } }
            public static string On14 { get { return "141\r\n"; } }
            public static string Off14 { get { return "140\r\n"; } }
            public static string On15 { get { return "151\r\n"; } }
            public static string Off15 { get { return "150\r\n"; } }
            public static string Ok { get { return "OK\r\n"; } }
        }
    }
}
